<template>
  <div id="search">
    <div class="search-wrap">
      <div>
        <div class="search-icon">
          <i class="fa fa-search"></i>
        </div>
        <input type="text" v-model="input" />
      </div>
    </div>
    <div class="search-content">
      <div class="search-title">
        <p>电影/电视剧/综艺</p>
      </div>
      <div class="content">
        <ul>
          <li v-for="item in Search" :key="item.id">
            <div class="first">
              <img :src="item.img" alt="" />
            </div>
            <div class="second">
              <p class="title">{{ item.title }}</p>
              <p class="font-color">{{ item.tag }}</p>
              <p class="font-color">{{ item.day }}</p>
            </div>
            <div class="third">
              <p class="score">{{ item.score }}</p>
            </div>
          </li>
        </ul>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "Search",
  data() {
    return {
      total: [],
      input: "",
    };
  },
  computed: {
    Search() {
      return this.total.filter((item) => {
        return item.title.indexOf(this.input) !== -1;
      });
    },
  },
  methods: {
    getTotal() {
      var that = this;
      axios
        .get("/mock/total.json")
        .then(function (response) {
          console.log(response);
          if (response.status == 200) {
            if (response.data && response.data.total) {
              that.total = response.data.total;
            }
          }
        })
        .catch(function (error) {
          console.log(error);
        });
    },
  },
  created() {
    this.getTotal();
  },
};
</script>

<style scoped>
/* search */
.search-wrap {
  width: 100%;
  height: 50px;
  display: flex;
  justify-content: center;
  align-items: center;
  background: whitesmoke;
}
.search-wrap > div {
  width: 90%;
  height: 25px;
  border: 1px solid #ccc;
  border-radius: 5px;
  background: white;
  display: flex;
}
.search-icon {
  width: 15%;
  height: 24px;
  text-align: center;
}
.search-wrap div i {
  line-height: 25px;
  font-size: 18px;
  font-weight: bold;
}
.search-wrap div input {
  outline: none;
  width: 85%;
  height: 24px;
  border-radius: 5px;
  padding: 0;
  border: 0;
}

/* title */
.search-title {
  width: 100%;
  height: 50px;
  font-size: 18px;
  border-top: 1px solid #ccc;
  border-bottom: 1px solid #ccc;
  color: #999;
  font-weight: bold;
  display: flex;
  justify-content: center;
  align-items: center;
}
.search-title p {
  display: block;
  width: 90%;
}

/* content */
#content {
  width: 100%;
}
ul {
  padding: 0;
}
li {
  display: flex;
  overflow: hidden;
  padding: 10px;
  border-bottom: 1px solid #ccc;
  column-gap: 5px;
}
img {
  max-width: 80%;
}

.title {
  font-weight: 700;
  font-size: 18px;
}
p {
  line-height: 25px;
}
.first {
  display: flex;
  width: 25%;
  justify-content: center;
}
.second {
  width: 50%;
}
.second > p:nth-of-type(3) {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.third {
  display: flex;
  width: 25%;
  text-align: center;
  line-height: 75px;
  justify-content: right;
}

.font-color {
  color: rgb(28, 27, 27);
  font-size: 15px;
}
.score {
  display: blcok;
  color: #f90;
  margin-left: 5px;
  font-weight: bold;
  font-size: 16px;
}
</style>